import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: () => import('../views/home/index.vue'),
      meta: { title: '首页' }
    },
    {
      path: '/order',
      name: 'order',
      component: () => import('../views/order/index.vue'),
      meta: { title: '订单' }
    },
    {
      path: '/mine',
      name: 'mine',
      component: () => import('../views/mine/index.vue'),
      meta: { title: '我的' }
    },
    {
      path: '/car-select',
      name: 'car-select',
      component: () => import('../views/car-select/index.vue'),
      meta: { title: '选择车型' }
    },
    {
      path: '/auth',
      name: 'auth',
      component: () => import('../views/auth/index.vue'),
      meta: { title: '实名认证' }
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/login/index.vue'),
      meta: { title: '登录' }
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('../views/register/index.vue'),
      meta: { title: '注册' }
    },
    {
      path: '/comment',
      name: 'comment',
      component: () => import('../views/comment/index.vue'),
      meta: { title: '评价' }
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/about/index.vue'),
      meta: { title: '关于我们' }
    },
    {
      path: '/car-detail/:id',
      name: 'CarDetail',
      component: () => import('@/views/car-detail/index.vue')
    },
    {
      path: '/order-confirm',
      name: 'OrderConfirm',
      component: () => import('@/views/order-confirm/index.vue'),
      meta: { title: '确认订单' }
    }
  ]
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title || '租车平台'
  next()
})

export default router
